<template>
  <el-header>
    <div class="l-content">
      <el-button size="small" plain @click="handClick">
        <el-icon :size="20">
          <Menu />
        </el-icon>
      </el-button>

      <el-breadcrumb separator="/" class="break">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="current.path" v-if="current">{{
          current.label
        }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img :src="getUrl('user')" alt="" class="el-img-head" />
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLoginOut">退出</el-dropdown-item>
          </el-dropdown-menu></template
        >
      </el-dropdown>
    </div>
  </el-header>
</template>

<script>
import { defineComponent, computed } from 'vue-demi'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
export default defineComponent({
  setup() {
    let store = useStore()
    let router = useRouter()
    const getUrl = (user) => {
      return new URL(`../assets/${user}.webp`, import.meta.url).href
    }

    let handClick = () => {
      store.commit('updateIsCollapse')
    }
    const current = computed(() => {
      return store.state.currentMenu
    })
    const handleLoginOut = () => {
      store.commit('cleanMenu')
      router.push({
        name: 'login',
      })
    }
    return {
      getUrl,
      handClick,
      current,
      handleLoginOut,
    }
  },
})
</script>

<style lang="less" scoped>
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background-color: #333;
}
.r-content {
  .el-img-head {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
.l-content {
  display: flex;
  align-items: center;
  h3 {
    color: #fff;
  }
  .el-button {
    margin-right: 20px;
  }
}
//.break /deep/ span {
//  color: #fff !important ;
//}

:deep(.break span) {
  color: #fff !important ;
  cursor: pointer !important;
}
</style>
